﻿<Page x:Class="MaxAlarm.Pages.LoginPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Pages="clr-namespace:MaxAlarm.Pages"
      xmlns:ViewModels="clr-namespace:MaxAlarm.ViewModels"
      xmlns:Settings="clr-namespace:MaxAlarm.Core.Settings;assembly=MaxAlarm.Core"
      xmlns:Authorization="clr-namespace:MaxAlarm.Core.Authorization;assembly=MaxAlarm.Core" mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="350"
	  Title="Login"
      Background="Transparent"
      Pages:LoginPage.ViewModel="{DynamicResource LoginPageViewModel}">
    
    <Page.Resources>
        <ViewModels:LoginPageViewModel x:Key="LoginPageViewModel"
                                       PageManager="{StaticResource PagesManager}">
        </ViewModels:LoginPageViewModel>
    </Page.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Border Background="{StaticResource DefaultBackgroundBrush}" >
            <Border VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Padding="40"
                    BorderThickness="1"
                    BorderBrush="LightGray"
                    Background="{StaticResource MinOpacityBrush}"
                    SnapsToDevicePixels="True">
                <Grid VerticalAlignment="Center"
                      HorizontalAlignment="Center" 
                      DataContext="{Binding Path=ViewModel, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Pages:LoginPage}}}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <Grid Visibility="{Binding Path=IsBusy, Source={x:Static Authorization:LoginManager.Instance}, Converter={StaticResource BooleanToVisibilityConverter}}"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Center"
                          Grid.Row="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Path=BusyMessage, Source={x:Static Authorization:LoginManager.Instance}}"
                                   Style="{StaticResource BigWhite}"
                                   Grid.Row="1"
                                   Margin="5"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"/>

                        <ProgressBar Style="{StaticResource WaitProgress}"
                                     Width="300"
                                     Height="20"
                                     Grid.Row="0"/>

                    </Grid>

                    <TextBlock Style="{StaticResource BigWhite}"
                               Visibility="{Binding Path=HasError, Converter={StaticResource BooleanToVisibilityConverter}}"
                               Text="{Binding Path=ErrorMessage}"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Center"
                               FontSize="13"
                               Foreground="#FF9292"
                               MaxWidth="300"
                               TextWrapping="WrapWithOverflow"/>

                    <Grid VerticalAlignment="Center"
                          HorizontalAlignment="Center"
                          Grid.Row="1"
                          Width="300"
                          Visibility="{Binding Path=IsBusy, Source={x:Static Authorization:LoginManager.Instance}, Converter={StaticResource BooleanToVisibilityInvertedConverter}}">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="150" />
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="Login:" Style="{StaticResource BigWhite}"
                                   Margin="5"
                                   Grid.Row="1"
                                   HorizontalAlignment="Right"/>

                        <ComboBox Grid.Column="1"
                                  Grid.Row="1"
                                  VerticalAlignment="Center"
                                  HorizontalAlignment="Stretch"
                                  Margin="5,0,5,0"
                                  Height="25"
                                  IsEditable="True"
                                  Text="{Binding Path=Login}"
                                  IsSynchronizedWithCurrentItem="True"
                                  IsTextSearchEnabled="True"
                                  ItemsSource="{Binding Source={x:Static Settings:SettingsManager.Instance}, Path=Settings.AccountsSettings.Accounts}"
                                  DisplayMemberPath="Login"
                                  SelectionChanged="SelectedLoginChanged"
                                  SelectedIndex="0"/>


                        <TextBlock Text="Password:" Style="{StaticResource BigWhite}"
                                   Margin="5"
                                   Grid.Row="2"
                                   HorizontalAlignment="Right"/>
                        <PasswordBox Grid.Column="1"
                                     Grid.Row="2"
                                     VerticalAlignment="Center"
                                     HorizontalAlignment="Stretch"
                                     Margin="5,0,5,0"
                                     Height="25"
                                     Style="{StaticResource PasswordBox}"
                                     PasswordChar="■"
                                     x:Name="PasswordBox"
                                     PasswordChanged="PasswordChanged"/>

                        <CheckBox IsChecked="{Binding Path=SavePassword}"
                                  Grid.Row="3"
                                  Grid.Column="1"
                                  Margin="5">
                            <CheckBox.Content>
                                <TextBlock Text="Save password" Style="{StaticResource BigWhite}"/>
                            </CheckBox.Content>
                        </CheckBox>

                        <StackPanel Grid.Row="4"
                                    Grid.ColumnSpan="2"
                                    Orientation="Horizontal"
                                    HorizontalAlignment="Right"
                                    Margin="0,10,5,0">

                            <Button Margin="10"
                                    Style="{StaticResource LoginButtons}"
                                    Command="{x:Static ViewModels:LoginPageViewModel.LoginCommand}">
                                <Button.Content>
                                    <TextBlock Text="Login" 
                                   Style="{StaticResource BigWhite}"
                                   Grid.Row="1"/>
                                </Button.Content>
                            </Button>

                            <Button Margin="10,10,0,10" 
                                    Style="{StaticResource LoginButtons}"
                                    Command="{x:Static ViewModels:LoginPageViewModel.CancelCommand}">
                                <Button.Content>
                                    <TextBlock Text="Cancel" 
                                               Style="{StaticResource BigWhite}"
                                               Grid.Row="1"/>
                                </Button.Content>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Border>
        </Border>
        
        <Canvas Background="{StaticResource LineBrush}"
				            Height="1"
				            HorizontalAlignment="Stretch"
				            VerticalAlignment="Bottom"
				            Margin="2,0,2,0"
                            Grid.Row="0"/>
        
        <Border Grid.Row="1"
                Background="Transparent">
            
            <Grid x:Name="BottomGrid" 
                  Background="Transparent">
                <StackPanel Grid.Row="2"
                            Margin="0,3,0,3"
                            Orientation="Horizontal"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Background="Transparent">

                    <Button Style="{StaticResource BottomButtonStyle}"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            ToolTip="Settings"
                            Command="{x:Static ViewModels:MainWindowViewModel.SettingsCommand}">
                        
                        <Canvas Background="{StaticResource SettingsBrush}"
							    Width="32"
							    Height="32" />
                    </Button>



                </StackPanel>

            </Grid>
        </Border>

    </Grid>
</Page>
